﻿Imports Oracle.DataAccess.Client
Imports System.Data.OleDb

Partial Class DenunciasModificar
    Inherits System.Web.UI.Page
    Private x As Integer
    Private Cmd As OracleCommand
    Private dt As Data.DataTable
    Private Cnx As OracleConnection
    Private oradb As String = "Data Source=XE;User Id=SIRA;Password=SIRA123;"
    Private Sql As String
    Private Aux As String
    Private dr As OracleDataReader

    Protected Sub LiberarRecursos()
        Cnx.Close()
        Cmd.Dispose()
        Cnx.Dispose()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lblUserNick.Text = Session("VarSessionUserNick")
        lblUserNombre.Text = Session("VarSessionUserNombre")
        lblUserIdCategoria.Text = Session("VarSessionUserIdCategoria")
        lblUserCategoria.Text = Session("VarSessionUserCategoria")
        lblUserIdComisaria.Text = Session("VarSessionUserIdComisaria")
        lblUserComisaria.Text = Session("VarSessionUserComisaria")
        lblUserIdNodo.Text = Session("VarSessionUserIdNodo")
        lblUserNodo.Text = Session("VarSessionUserNodo")
        lblUserIdUsuario.Text = Session("VarSessionUserIdUsuario")
        lblFechaMod.Text = Today
        If Not IsPostBack Then
            CargarDDLPatentes()
        End If

    End Sub

    Protected Sub CargarDDLPatentes()
        Cnx = New OracleConnection(oradb)
        Sql = "select * from Denuncias"
        DDLPatentes.Items.Clear()
        Try
            Cnx.Open()
            Cmd = New OracleCommand(Sql, Cnx)
            Cmd.CommandType = Data.CommandType.Text
            Cmd.ExecuteNonQuery()
            dr = Cmd.ExecuteReader()
            DDLPatentes.Items.Add("Su Elección")
            While dr.Read()
                DDLPatentes.Items.Add(dr.Item("Patente"))
            End While
            DDLPatentes.SelectedIndex = 0
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        Finally
        End Try
        LiberarRecursos()
    End Sub
    Protected Sub btnAceptar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        If Page.IsValid Then
        Else
            labelMessage.Text = "Error en carga de datos - Proceso btnAceptar_Click - DenunciasModificar.aspx"
            Exit Sub
        End If
        If txtObservaciones.Text.Length = 0 Then txtObservaciones.Text = "-"
        Cnx = New OracleConnection(oradb)
        Cnx.Open()
        Try
            Sql = "UPDATE Denuncias set " & _
                   "IdComisaria_Mod='" & Session("VarSessionUserIdComisaria") & "'," & _
                   "IdNodo_Mod='" & Session("VarSessionUserIdNodo") & "'," & _
                   "IdUsuario_Mod='" & Session("VarSessionUserIdUsuario") & "'," & _
                   "Fecha_Mod='" & lblFechaMod.Text & "'," & _
                   "Captura='N'," & _
                   "Recuperado='S'," & _
                   "Observaciones='" & txtObservaciones.Text & "' " & _
                   "WHERE Patente='" & DDLPatentes.SelectedValue & "'"
            Cmd = New OracleCommand(Sql, Cnx)
            Cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox("No puedo Actualizar (UPDATE) tabla Denuncias " & vbCrLf & ex.Message, MsgBoxStyle.Critical, _
                   "Error proceso btnAceptar_Click panel Edicion btnAceptarEdicion - DenunciasModificar.aspx")
            MsgBox(ex.Message.ToString())
        Finally
        End Try
        LiberarRecursos()
        MsgBox("Modificado con exito " & vbCrLf & "Patente " & DDLPatentes.SelectedValue, MsgBoxStyle.OkOnly, _
        "Carga exitosa")
        LimpiarPanelCargar()
        PanelModificar.Visible = False
        PanelSeleccion.Visible = True

    End Sub
    Protected Sub LimpiarPanelCargar()
        DDLPatentes.SelectedIndex = 0
        lblPatente.Text = ""
        txtObservaciones.Text = ""
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        PanelModificar.Visible = False
    End Sub

    Protected Sub btnAceptarSeleccion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAceptarSeleccion.Click
        If DDLPatentes.SelectedValue = "Su Elección" Then
            lblCrtlDDLPatentes.Visible = True
            PanelModificar.Visible = False
            Exit Sub
        Else
            lblCrtlDDLPatentes.Visible = False
            PanelModificar.Visible = True
            PanelSeleccion.Visible = False
        End If
        Cnx = New OracleConnection(oradb)
        Sql = "select * from Denuncias WHERE Patente = '" & DDLPatentes.SelectedValue & "'"
        Try
            Cnx.Open()
            Cmd = New OracleCommand(Sql, Cnx)
            Cmd.CommandType = Data.CommandType.Text
            dr = Cmd.ExecuteReader()
            dr.Read()
            lblPatente.text = dr.Item("Patente")
            txtObservaciones.Text = dr.Item("Observaciones")
        Catch ex As Exception
            MsgBox("No puedo abrir tabla Denuncias " & vbCrLf & ex.Message, MsgBoxStyle.Critical, _
                   "Error proceso AceptarPanelSeleccion - DenunciasModificar.aspx")
            MsgBox(ex.Message.ToString())
        Finally
        End Try
        LiberarRecursos()

    End Sub

    Protected Sub btnSalirPanelEdicion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSalirPanelEdicion.Click
        PanelSeleccion.Visible = False
    End Sub

    Protected Sub DDLPatentes_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLPatentes.SelectedIndexChanged

    End Sub
End Class
